package cn.jcby.app.lebu.controller;


import cn.jcby.app.lebu.controller.req.AddPersonMotionReq;
import cn.jcby.app.lebu.controller.req.UpdatePersonMotionReq;
import cn.jcby.app.lebu.controller.res.PersonMotionStatRes;
import cn.jcby.app.lebu.service.UserPersonMotionService;
import cn.jcby.app.lebu.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



/**
 * 个人运动
 *
 * @author lht
 * @email 
 * @date 2023-12-07 15:13:35
 */
@RestController
@RequestMapping("/person/motion")
@Api(tags="个人运动")
public class UserPersonMotionController {
    @Autowired
    private UserPersonMotionService userPersonMotionService;

    //根据运动类型统计总里程、本月里程
    @GetMapping("/stat/{motionType}")
    @ApiOperation("统计")
    @ApiResponses({
          @ApiResponse(code = 200,message = "ok",response = PersonMotionStatRes.class)
    })
    public Result statMotion(@PathVariable("motionType")String motionType){

        PersonMotionStatRes res = userPersonMotionService.stat(motionType);
        return Result.ok().put("data", res);
    }


    /**
     * 保存
     */
    @PostMapping("/start")
    @ApiOperation("开始")
    public Result save(@RequestBody @Validated AddPersonMotionReq userPersonMotion){
        userPersonMotionService.add(userPersonMotion);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/end")
    @ApiOperation("结束")
    public Result update(@RequestBody @Validated UpdatePersonMotionReq req){
      userPersonMotionService.updateBy(req);
      return Result.ok();
    }


}
